package com.server;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import com.client.GreetingService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
		GreetingService {

	public String greetServer(String input)
	{
		String TotalContent = "";
		try {
			URL OAuthUrlRead = new URL(input);
			URLConnection conn = OAuthUrlRead.openConnection();
	        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			String inputLine = "";
			while ((inputLine = in.readLine()) != null)
	        {
				TotalContent = TotalContent + inputLine;
	        }
			//TotalContent = in.readLine();
	        in.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			return "failure " + e.getMessage();
		}
		TotalContent = TotalContent.split("access_token=")[1];
		return TotalContent;
	}
}
